import toast from './ty-toast.vue'
import './index.css'
// import WebFont from 'webfontloader'
let instance = null;
// WebFont.load({
//     custom: {
//         families: ['iconfont'],
//     }
// });
const preloadEle = document.createElement('i')
preloadEle.setAttribute('preload-font', '')
document.body.appendChild(preloadEle)
export function Toast(options) {
    if (!instance) {
        const dom = document.createElement('div')
        // 一定要先插入到真实dom树中。
        document.body.appendChild(dom)
        const vm = new options({
            render(h) {
                return h(toast)
            }
        }).$mount(dom)
        instance = vm.$children[0]
        return;
    }
    if (typeof options === 'string') {
        instance.message({
            message: options
        })
    } else if (typeof options === 'object') {
        instance.custom(options)
    }
}
Toast.loading = function (options) {
    instance.loading(options)
}
Toast.clear = function() {
    instance.clear()
}